package stool.juc.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author Felix YF Dong
 * @Description
 * @Date 2023/2/20
 */
public class CompletableFutureTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> completableFuture=CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName()+" 没有返回，update mysql ok ");
        });
        completableFuture.get();

        //异步回调
        CompletableFuture<Integer> completableFuture1=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+" completableFuture1 ");
//            int a=10/0;
            return 1024;
        });
        System.out.println(completableFuture1.whenComplete((t, u) -> {
            System.out.println("**t:" + t);
            System.out.println("**u:" + u);
        }).exceptionally(f -> {
            System.out.println("**exception:" + f.getMessage());
            return 4444;
        }).get());
    }
}
